package com.asiainfo.ai.gateway.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.locks.ReentrantLock;

public class LockUtils {

	private static final Logger log = LoggerFactory.getLogger(LockUtils.class);

	private static final ReentrantLock incrementLock = new ReentrantLock();

	public static void lockIncrement() {
		try {
			log.info("推理服务访问次数Lock等待开启");
			incrementLock.lock();
			log.info("推理服务访问次数Lock已开启 ");
		}
		catch (Exception e) {
			log.error("推理服务访问次数Lock开启失败：", e.getMessage());
		}

	}

	public static void unLockIncrement() {
		try {
			if (incrementLock.isLocked()) {
				incrementLock.unlock();
				log.info("推理服务访问次数Lock已释放 ");
			}
		}
		catch (Exception e) {
			log.error("推理服务访问次数Lock释放失败：", e.getMessage());
		}
	}

}
